//////////////////////////////////////////////////////////////////////
//!\file FileSystemManager.hpp
//!\brief Does filesearch and all other file processings in a separate thread.
//!\author timmsusa@googlemail.com
//////////////////////////////////////////////////////////////////////

#ifndef FILESYSTEMMANAGER_HPP
#define FILESYSTEMMANAGER_HPP

#include <QObject>
#include <QDir>
#include <QString>
#include "FlacTrack.hpp"
#include <QVector>
#include <QFileInfo>
#include <QSet>
#include "FileStorageWorkData.hpp"
#include "Persistence.hpp"
#include "AlbumDataModel.hpp"

class FileSystemManager : public QObject//, public FlacMetadataManager
{
    Q_OBJECT
public:
    FileSystemManager(QObject *parent = 0);
    ~FileSystemManager();
private:
    void deepScanForFlac( QDir dir, QVector < FlacTrack >& listOfFoundEntries );
    void copyOverwrite(bool isFile, QString source, QString dest);
    void compareFlacLists();
    bool rmDir(const QString &dirName);
    bool isAlbumDuplicate(const Album& updateAlbum, const Album& collAlbum);

    QString getLastPartFromPath(const QString& inPath);
    QString getSubFolderPart(const QString inPath);


signals:
    void sigFlacFound(QString file);
    void sigFolderFound(Album album);
    void sigSearchInMusicCollectionFinished();
    void sigSearchInFileIncomingFinished();
    void sigFlacListComparisonFinished(QVector < Album > diffList);
    void sigCopyProgress(int perc);
    void sigEnableDeepScan(bool enable);
    void sigStopScanMusicCollection();
    void sigStopScanUpdateCollection();
    void sigInitMusicCollectionByPath(QString path);
    void sigInitUpdateCollectionByPath(QString path);

public slots:
    void slotSearchInMusicCollection(QString path);
    void slotSearchInFileIncoming(QString path);
    void slotCompareFlacLists();
    void slotRemoveDir(const QString & dirName);
    void slotCopy(bool isFile, QString source, QString dest);
    void slotCopyAllFolderTo(QStringList srcPaths, QStringList destPath);
    void slotResetFileCounter();
    void slotEnableDeepScan(bool enable);
    void slotInitOfMusicCollectionModelFinished();
    void slotInitOfUpdateCollectionModelFinished();

private:
    Persistence         m_Persistence;
    bool                m_DeepScanEnabled;
    //FileStorageWorkData *m_pFileStorage;
    AlbumDataModel m_MusicCollectionModel;
    AlbumDataModel m_UpdateCollectionModel;
    QVector < Album > m_DiffCollection;
    int             m_FilesToCopyCount;
};

#endif // FILESYSTEMMANAGER_HPP
